package com.zxy.car.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.zxy.car.entity.RecordEntity;
import com.zxy.car.service.RecordService;
import com.zxy.common.utils.PageUtils;
import com.zxy.common.utils.R;



/**
 * 
 *
 * @author zxy
 * @email 1695483548@qq.com
 * @date 2022-04-15 10:01:02
 */
@RestController
@RequestMapping("car/record")
public class RecordController {
    @Autowired
    private RecordService recordService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = recordService.queryPage(params);

        return R.ok().put("page", page);
    }

    @RequestMapping("/list1")
    public R list1(@RequestParam Map<String, Object> params){
        PageUtils page = recordService.queryPage1(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		RecordEntity record = recordService.getById(id);

        return R.ok().put("record", record);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody RecordEntity record){
		recordService.save(record);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody RecordEntity record){
		recordService.updateById(record);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		recordService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /*
     * 加入订单
     * */
    @RequestMapping("/addRecord/{loginName}/{buymoney}/{plan}/{monthpay}/{naotherpay}/{sum}")
    public R addRecord(@PathVariable("loginName")String loginName,@PathVariable("buymoney")Double buymoney,@PathVariable("plan")Integer plan,@PathVariable("monthpay")Double monthpay,@PathVariable("naotherpay")Double naotherpay,@PathVariable("sum")Double sum){
        recordService.addRecord(loginName,buymoney,plan,monthpay,naotherpay,sum);
        return R.ok();
    }

    /*
     * 审核
     * */
    @RequestMapping("/updaterecord/{id}/{loginName}")
    public R updaterecord(@PathVariable("id")Integer id,@PathVariable("loginName")String loginName){
        recordService.updaterecord(id,loginName);
        return R.ok();
    }
}
